package com.ld.security.server.admin.modules.ge.api;

import com.ld.security.common.tomcat.anno.AjaxLogKey;
import com.ld.security.server.admin.modules.ge.entity.GeTableEntity;
import com.ld.security.server.admin.modules.ge.po.TableQueryPo;
import com.ld.security.server.admin.modules.ge.po.TableSaveDetailsPo;
import com.ld.security.server.admin.modules.ge.service.IGeTableService;
import com.ld.security.server.admin.modules.ge.vo.TableDetailsVo;
import com.ld.security.common.mybatis.base.po.IdPo;
import com.ld.security.common.mybatis.base.po.PagePo;
import com.ld.security.common.mybatis.base.vo.DataVo;
import com.ld.security.common.mybatis.base.vo.ListVo;
import com.ld.security.common.mybatis.base.vo.NodeVo;
import com.ld.security.common.tomcat.base.api.SuperApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags="表Api管理")
@RequestMapping("/api/geTable")
public class GeTableApi extends  SuperApi<GeTableEntity> {

    @Autowired
    IGeTableService iGeTableService;

    @AjaxLogKey
    @ApiOperation("修改表模型")
    @RequestMapping(value = "/tableSaveDetails",method = RequestMethod.POST)
    public DataVo tableSaveDetailsPo(@RequestBody TableSaveDetailsPo po){
        iGeTableService.tableSaveDetailsPo(po);
        return DataVo.ofMsg("修改表模型成功");
    }

    @AjaxLogKey
    @ApiOperation("获得表模型详情")
    @RequestMapping(value = "/getTableDetails",method = RequestMethod.POST)
    public DataVo tableSaveDetailsPo(@RequestBody IdPo po){
        TableDetailsVo vo =  iGeTableService.getTableDetails(po.getId() );
        return DataVo.of(vo);
    }

    @ApiOperation("获得表树形结构")
    @RequestMapping(value = "/getTableTree",method = RequestMethod.POST)
    public DataVo getTableTree(@RequestBody PagePo<TableQueryPo> po){
        List<NodeVo> vo =  iGeTableService.getTableTree(po);
        return DataVo.of(ListVo.of(vo));
    }


    @ApiOperation("获得字段树形结构")
    @RequestMapping(value = "/getFieldTree",method = RequestMethod.POST)
    public DataVo getFieldTree(@RequestBody PagePo<TableQueryPo> po){
        List<NodeVo> vo =  iGeTableService.getTableTree(po);
        for (NodeVo nodeVo : vo) {
            nodeVo.setId("0");
        }
        return DataVo.of(ListVo.of(vo));
    }

}
